@extends('admin.common.base-master')

@section('html-head')
    <link href="{{url('css/jquery.form.css')}}" type="text/css" rel="stylesheet" />
    <script src="{{url('/js/lib/jquery.form.js')}}"></script>


    @endsection

    @section('html-body')
            <!-- content start -->
    <div id="content">
        <!-- cur-position start -->
        <div id="cur-position">
            <span class="tit">当前位置：</span>
            <a href="{{route('Admin.Home.topicList')}}">问答管理</a>
            <em>></em>
            <a href="#">添加/修改问题</a>
        </div>
        <!-- cur-position end -->

        <div class="gg-step">
            <form  id="advform">
                <input type="hidden" name="id" id="id" value="@if($sysTopic) {{$sysTopic->id}} @endif"/>

                <div class="gg-list">
                    <label class="tit">题目内容：</label>
                    <div class="cont">
                        <select name="type" id="type">
                            <option value="1" @if($sysTopic && $sysTopic->type == 1)selected  @endif>单选</option>
                            <option value="2" @if($sysTopic && $sysTopic->type == 2)selected  @endif>多选</option>
                        </select>
                    </div>
                </div>

                <div class="gg-list">
                    <label class="tit">题目内容：</label>
                    <div class="cont">
                        <textarea name="topic" id="topic" cols="70" rows="10" placeholder="请输入题目内容">@if($sysTopic) {{$sysTopic->topic}} @endif</textarea>
                        <p class="text">可输入2-40个字符（一个汉字等于2个字符）</p>
                    </div>
                </div>

                <div class="gg-list">
                    <label class="tit">题目分类：</label>
                    <div class="cont">
                        <select name="classify_id" id="classify_id">
                            @if(count($classify) > 0)
                                @foreach($classify as $c)
                                    <option value="{{$c->id}}" @if( $sysTopic &&$sysTopic->classify_id == $c->id) selected @endif>{{$c->name}}</option>
                                @endforeach
                            @endif
                        </select>
                    </div>
                </div>

                <div class="gg-list">
                    <label class="tit">题目分数：</label>
                    <div class="cont">
                        <input type="text" id="fraction" name="fraction" placeholder="请输入题目分数" value="@if($sysTopic) {{$sysTopic->fraction}} @endif">
                        <p class="text">可输入数值</p>
                    </div>
                </div>

            </form>
            <div class="gg-list" >
                <label class="tit">&nbsp;</label>
                <div class="cont" >
                    <a href="javascript:;" class="next-step" id="btn_send">提交</a>
                </div>
            </div>
        </div>
    </div>

    <!-- content end -->
    <script>
        $(function() {

            $('#btn_send').click(function () {
                var topic      = $('#topic').val();
                var classifyId = $('#classify_id option:selected').val();
                var type       = $('#type option:selected').val();
                var fraction   = $('#fraction').val();
                var id         = $('#id').val();

                $.ajax({
                    url:"{{route('Api.Admin.sys.setTopic')}}",
                    type:'post',
                    dataType:'json',
                    data:{
                        topic:topic,
                        classify_id:classifyId,
                        type:type,
                        fraction:fraction,
                        id:id
                    },
                    success:function (obj) {
                        if(obj.level == 'success'){
                            noty({text:obj.message,type:obj.level,timeout:600,
                                callback:{
                                    afterClose:function(){
                                        window.location.href="{{route('Admin.Home.topicList')}}";
                                    }
                                }
                            });
                        }else {
                            noty({text:obj.message,type:obj.level,timeout:600});
                        }
                    },
                    error:function (obj) {
                        console.log(obj);
                    }
                });
            });
        });
    </script>
@endsection